import com.deepoove.poi.XWPFTemplate;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;

/**
 * @author 别人
 */
public class WordUtils {

    /**
     * 生成Word
     *
     * @param bytes    模板
     * @param fileName 文件名
     * @param map
     * @throws IOException
     */
    public static File docTemplateReplace(byte[] bytes, String fileName, Map<String, Object> map) throws IOException {
        System.out.println("生成中...");
        //读模板文件
        XWPFTemplate template = XWPFTemplate.compile(new ByteArrayInputStream(bytes)).render(map);
        String localhostFileName = fileName;
        FileOutputStream out = new FileOutputStream(localhostFileName);
        template.write(out);
        out.flush();
        out.close();
        System.out.println("生成 成功...");
        return new File(localhostFileName);
    }


    /**
     * POI EL 导出
     *
     * @param bytes
     * @param fileName
     * @param map
     * @throws IOException
     */
    public static void docTemplateReplace(String httpurl, byte[] bytes, String fileName, Map<String, Object> map) throws IOException {
        System.out.println("生成中...");
        //读模板文件
        XWPFTemplate template = XWPFTemplate.compile(new ByteArrayInputStream(bytes)).render(map);
        //生成新的文件
        // docx文件名
        String localhostFileName = fileName;
        System.out.println("=====docx文件名：" + localhostFileName);
        FileOutputStream out = new FileOutputStream(localhostFileName);
        template.write(out);
        out.flush();
        out.close();
    }

}
